package cn.iocoder.yudao.module.wengfu.service.approval;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.wengfu.controller.admin.approval.vo.*;
import cn.iocoder.yudao.module.wengfu.dal.dataobject.approval.SampleApprovalInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.wengfu.dal.mysql.approval.SampleApprovalInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.wengfu.enums.ErrorCodeConstants.*;

/**
 * 样品审批 Service 实现类
 *
 * @author yzs
 */
@Service
@Validated
public class SampleApprovalInfoServiceImpl implements SampleApprovalInfoService {

    @Resource
    private SampleApprovalInfoMapper sampleApprovalInfoMapper;

    @Override
    public Long createSampleApprovalInfo(SampleApprovalInfoSaveReqVO createReqVO) {
        // 插入
        SampleApprovalInfoDO sampleApprovalInfo = BeanUtils.toBean(createReqVO, SampleApprovalInfoDO.class);
        sampleApprovalInfoMapper.insert(sampleApprovalInfo);

        // 返回
        return sampleApprovalInfo.getId();
    }

    @Override
    public void updateSampleApprovalInfo(SampleApprovalInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateSampleApprovalInfoExists(updateReqVO.getId());
        // 更新
        SampleApprovalInfoDO updateObj = BeanUtils.toBean(updateReqVO, SampleApprovalInfoDO.class);
        sampleApprovalInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteSampleApprovalInfo(Long id) {
        // 校验存在
        validateSampleApprovalInfoExists(id);
        // 删除
        sampleApprovalInfoMapper.deleteById(id);
    }

    @Override
        public void deleteSampleApprovalInfoListByIds(List<Long> ids) {
        // 删除
        sampleApprovalInfoMapper.deleteByIds(ids);
        }


    private void validateSampleApprovalInfoExists(Long id) {
        if (sampleApprovalInfoMapper.selectById(id) == null) {
            throw exception(SAMPLE_APPROVAL_INFO_NOT_EXISTS);
        }
    }

    @Override
    public SampleApprovalInfoDO getSampleApprovalInfo(Long id) {
        return sampleApprovalInfoMapper.selectById(id);
    }

    @Override
    public PageResult<SampleApprovalInfoDO> getSampleApprovalInfoPage(SampleApprovalInfoPageReqVO pageReqVO) {
        return sampleApprovalInfoMapper.selectPage(pageReqVO);
    }

}